package com.bw.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.EduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class EduController {
    @Autowired
    EduService eduService;
    @RequestMapping("/findTotal")
    public Object findTotal(){
        List<Map> list = eduService.findTotal();
        JSONObject jsonObject = new JSONObject();
         jsonObject.put("status",0);
         jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray xArray = new JSONArray();
        for (Map map : list) {
            xArray.add(map.get("name"));
        }
        dataObject.put("categories",xArray);
        JSONArray yArray = new JSONArray();
        JSONObject yObject = new JSONObject();
        yObject.put("name","试卷名称");
        JSONArray dataArray = new JSONArray();
        for (Map map : list) {
           dataArray.add(map.get("ascore"));
        }
        yObject.put("data",dataArray);
        yArray.add(yObject);
        dataObject.put("series",yArray);


         jsonObject.put("data",dataObject);
        return jsonObject;
    }
     @RequestMapping("/findStatus")
    public Object findStatus(String status){
         List<Map> list = eduService.findStatus(status);
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("status",0);
         jsonObject.put("msg","");
         jsonObject.put("data",list.get(0).get("sum(final_amount)"));
         return jsonObject;
     }
     @RequestMapping("/findcha")
     public Object findcha(){
         List<Map> list = eduService.findcha();
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("status",0);
         jsonObject.put("msg","");
         JSONObject dataObject = new JSONObject();
         JSONArray mapArray = new JSONArray();
         for (Map map : list) {
             JSONObject mapObject = new JSONObject();
             mapObject.put("name",map.get("name"));
             mapObject.put("value",map.get("total"));
             mapArray.add(mapObject);
         }
         dataObject.put("mapData",mapArray);
         dataObject.put("valueName","总成交额");

         jsonObject.put("data",dataObject);
         return jsonObject;
     }
     @RequestMapping("/findce")
     public Object findce(){

         return eduService.findce();
     }
    @RequestMapping("/findmax")
    public Object findmax(){

        return eduService.findmax();
    }
    @RequestMapping("/findcount")
    public Object findcount(){

        return eduService.findcount();
    }
    @RequestMapping("/finduser")
    public Object finduser(){

        return eduService.finduser();
    }
}
